<template>
  <div id="SearchPage">
    <div class="wrap">
      <div class="content">
      <div class="mt25"><ul class="cooklist">
        <li class="cookdetail" v-for="recipe in recipelist" :key="recipe.menuId">
          <router-link :to="{name: 'DishDetails',params: {id: recipe.menuId}}">
            <img :src="recipe.menuSrc" alt="" class="cook-img">
          </router-link>
      <div class="cook-info">
        <router-link :to="{name: 'DishDetails',params: {id: recipe.menuId}}">
            <div class="cook-nickname">{{recipe.menuName}}</div>
        </router-link>
        <p class="major">{{recipe.introduce}}</p>
       <div class="score">
         <span>浏览：
          <b>{{recipe.doh}}</b>
         </span>
         <span>
           收藏：
           <b>{{recipe.collection}}</b>
         </span>
       </div>
        <router-link :to="{name: 'CenterRecipes',params: {  userId:recipe.userId}}">
            <div class="auther"><img :src="recipe.headImg" alt="" class="auther-head">{{recipe.nickname}}</div>
        </router-link>
       </div>
     </li>
     </ul></div>
      </div>
    </div>
<span v-show="displaycontent" class="nocontent">暂时没有更多的内容~</span>

    <div v-show="buttonpage">
 <el-pagination  background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNow"
      :page-sizes="[1, 2, 5, 10]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination></div>
  </div>
</template>
<script>
// import cookie from '../../../cookien/index'
// import LoginVue from '../../Login.vue'
export default {
  name: 'SearchPage',
  data () {
    return {
      total: 0,
      recipelist: [],
      pageNow: 1,
      pageSize: 10,
      searchmessage: '',
      displaycontent: false,
      buttonpage: true
    }
  },

  created () {
    this.SearchRecipe()
  },
  methods: {

    // 搜索食谱
    SearchRecipe () {
      this.$axios({
        method: 'get',
        url: '/Menu/Visitor/findMenuByNameLike',
        params: {
          pageNow: this.pageNow,
          pageSize: this.pageSize,
          key: this.$store.state.searchMsg
        },
        headers: {
          token: this.$store.state.token
        }
      }).then(data => {
        console.log(data.data.object.list)
        if (data.data.object.list.length === 0) {
          this.displaycontent = !this.displaycontent
          this.buttonpage = !this.buttonpage
        } else {
          this.recipelist = data.data.object.list
          this.total = data.data.object.list.length
        }
      })
    },
    // 监测当前一页有几条数据
    handleSizeChange (size) {
      this.pageSize = size
      this.SearchRecipe()
    },
    // 监测当前页数
    handleCurrentChange (num) {
      this.pageNow = num
      this.SearchRecipe()
    }
  }
}
</script>
<style lang="less" scoped>
.wrap{
  min-height: 268px;
}
.nocontent{
    margin: 40px;
    display: block;
    text-align: center;
    color: #999;
}
a{
  text-decoration: none;
  padding: 0 10px;
    font-size: 14px;
    color: #333;
}
.content{
  width: 1000px;
  margin: 0 auto;
  // background-color: yellow;
  }
  .sort-more{
    margin: 25px 0;
  }
  .mt25{
    margin-top: 25px;
    .cooklist{
      list-style: none;
      display: flex;
    flex-wrap: wrap;
      .cookdetail{
        padding-bottom: 40px;
        .cook-img{
          width: 180px;
          height: 125px;
          float: left;
          border-radius: 8px;
          overflow: hidden;
          margin-right: 15px;
        }
        .cook-info{width: 495px;
    height: 125px;
    float: left;
    // background-color: aquamarine;
       .cook-nickname{
         padding-top: 8px;
        font-size: 18px;
        font-weight: bold;
        overflow: hidden;
        line-height: 18px;
        display: inline-block;
        width: 483px;
        margin-bottom: 14px;
        &:hover{
          color: #FFB31A
        }
       }
       .major{
         text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        font-size: 14px;
        color: #2a2a2a;
        line-height: 14px;
        text-indent: 12px;
       }
       .score{
        //  width: 91px;
         height: 16px;
         margin: 11px 12px 10px;
         span{
           text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
          font-size: 14px;
          color: #2a2a2a;
          line-height: 14px;
          vertical-align: middle;
         }
         .auther{
           font-size: 14px;
          line-height: 22px;
          height: 24px;
         }
       }
    }
      }
    }
    }

.auther-head{
  display: inline-block;
  width: 21px;
  height: 21px;
  vertical-align: middle;
  border-radius: 50%;
    position: relative;
    top: -2px;
    padding-right: 10px;
}
.el-pagination{
  text-align: center;
}
</style>
